package hb.software.service.exam.impl;

import hb.software.exam.dao.ExamDao;
import hb.software.exam.entity.Exam;
import hb.software.service.exam.ExamManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers;
import edu.zut.hb.software.base.service.impl.GenericStudentManagerImpl;

import java.util.List;

public class ExamManagerImpl extends GenericStudentManagerImpl<Exam, Long> implements ExamManager {
	private ExamDao examDao;

	@Override
	public List<Exam> findByName(String name) {
		// 创建查询条件数据对象
		Exam queryObject = new Exam();
		queryObject.setExamname(name);
		ExampleMatcher matcher = ExampleMatcher.matching() // 构建对象
				.withMatcher("name", GenericPropertyMatchers.startsWith()) // 姓名采用“开始匹配”的方式查询
				.withIgnorePaths("dateCreated", "dateModified");
		// 创建实例并查询
		Example<Exam> ex = Example.of(queryObject, matcher);
		List<Exam> result = dao.findAll(ex);
		return result;
	}

	@Autowired
	public void setExamDao(ExamDao examDao) {
		this.examDao = examDao;
		this.dao = this.examDao;

	}

}
